package org.dromara.bzIns.controller.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.bzIns.domain.bo.InsCompanyBo;
import org.dromara.bzIns.domain.bo.InsInsureBo;
import org.dromara.bzIns.domain.bo.UserCarBo;
import org.dromara.bzIns.domain.vo.InsCompanyVo;
import org.dromara.bzIns.domain.vo.InsInsureVo;
import org.dromara.bzIns.domain.vo.UserCarVo;
import org.dromara.bzIns.service.IInsCompanyService;
import org.dromara.bzIns.service.IInsInsureService;
import org.dromara.bzIns.service.IUserCarService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class ApiController extends BaseController {

    //用户汽车
    private final IUserCarService userCarService;

    //保单记录
    private final IInsInsureService insInsureService;

    //保险公司信息
    private final IInsCompanyService insCompanyService;

    //保单首页
    @GetMapping("/getCarAndInsureList")
    public R<List<UserCarVo>> getCarAndInsureList() {
        return R.ok(userCarService.getCarAndInsureList());
    }

    //车辆管理--CRUD
    @GetMapping("/getUserCarList")
    public R<List<UserCarVo>> getUserCarList() {
        return R.ok(userCarService.getUserCarList());
    }
    @Log(title = "用户汽车", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/addUserCar")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserCarBo bo) {
        return toAjax(userCarService.insertByBo(bo));
    }
    @GetMapping("/getUserCar/{carId}")
    public R<UserCarVo> getInfo(@NotNull(message = "主键不能为空")
                                @PathVariable Long carId) {
        return R.ok(userCarService.queryById(carId));
    }
    @Log(title = "用户汽车", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/editUserCar")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserCarBo bo) {
        return toAjax(userCarService.updateByBo(bo));
    }
    @Log(title = "用户汽车", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteUserCar/{carIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] carIds) {
        return toAjax(userCarService.deleteWithValidByIds(List.of(carIds), true));
    }

    //买车险--显示报价
    @GetMapping("/getQuoteList")
    public R<List<UserCarVo>> getQuoteList() {
        return R.ok(userCarService.getQuoteList());
    }

    //买车险--显示公司信息
    @GetMapping("/getInsCompanyList")
    public R<List<InsCompanyVo>> getInsCompanyList() {
        return R.ok(insCompanyService.queryList(new InsCompanyBo()));
    }

    //查保单
    @GetMapping("/getInsureList")
    public R<List<InsInsureVo>> getInsureList() {

        return R.ok(insInsureService.queryListWithCompany());
    }

}
